﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.Master" Inherits="System.Web.Mvc.ViewPage<MethodWorx.CMS.UI.Areas.Administration.Models.UserViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <link href="<%=Url.Content("~/css/flexigrid/flexigrid.css")%>" rel="stylesheet" type="text/css" />
    <script src="<%=Url.Content("~/Scripts/flexigrid.js")%>" type="text/javascript"></script>

    <script language="javascript">
        $(document).ready(function () {
            $(".content").css("margin", "0px");
            var buttons = new Array();
            buttons.push({ text: 'Add New', hasText: false, id: 'addUser', icon: '<%=Url.Content("~/images/icons/user_add.png")%>' });
            buttons.push({ text: 'Configure View', hasText: false, id: 'configureView', icon: '<%=Url.Content("~/images/icons/cog.png")%>' });

            MethodWorx.CMS.Toolbar.setButtons(buttons, "#toolbar");
            buttons = new Array();



            $('#usergrid').flexigrid(
            {

                usepager: true,
                singleSelect: true,
                useRp: false,
                showTableToggleBtn: false,
                resizable: false
            });

            $(".pReload").parent().hide();
            $(".pReload").hide();

            resizeForm();

            //$("tr.erow td").css("background-color", "#EFEFEF");

            $("#addUser").click(function () {
                window.parent.openDialog("<%=Url.Content("~/Administration")%>/User/Add", "Add User", function (action) {
                    if (action == "save") {
                        //  refresh the grid
                        window.location.href = window.location.href;
                    }
                });
            });

            $("#configureView").click(function () {
                window.parent.openDialog("<%=Url.Content("~/Administration")%>/User/ConfigureView?type=<%=Model.CurrentUserType%>", "Configure View", function (action) {
                    if (action == "save") {
                        window.location.href = window.location.href;
                    }
                });
            });

            //  attach the resize form method
            $(window).resize(resizeForm);
        });

     function resizeForm() {
         $(".flexigrid").height($(window).height() - 60);
         $(".bDiv").height($(window).height() - 120);
         
        }


</script>
    <div style="margin:10px">
    <table id="usergrid">
    <thead>
        <tr>
            <th width="50"></th>
            <th width="200">User Name</th>
            <th width="200">Name</th>
            <th width="50">Admin</th>
            <th width="50">Active</th>
            <%
                if (this.Model.Attributes != null) {
                foreach(var attribute in this.Model.Attributes)
                {
                    %><th><%:attribute %></th><%
                }
            
                }
%>
        </tr>
    </thead>
    <tbody>
    <% if (this.Model.Users != null)
       {
           foreach (var user in this.Model.Users)
           {
    %>
    
                <tr>
                <td><a href="<%=user.Id%>" title="Edit"><img src="<%=Url.Content("~/Images/icons/application_edit.png")%>" /></a>&nbsp;&nbsp;
                <a href="<%=user.Id%>" title="Delete"><img src="<%=Url.Content("~/Images/icons/application_delete.png")%>" /></a></td>
                
                <td><%=user.Username%></td>
                <td><%=user.FirstName%>&nbsp;<%=user.LastName%></td>
                
                <%if (user.Administrator)
                  { %>
                <td style="text-align:center" ><img src="<%=Url.Content("~/images/icons/tick.png")%>" /></td>
                <%}
                  else
                  { %>
                   <td><img src="<%=Url.Content("~/images/icons/cross.png")%>" /></td>
                <%} %>
                <%if (user.Active)
                  { %>
                <td><img src="<%=Url.Content("~/images/icons/tick.png")%>" /></td>
                <%}
                  else
                  { %>
                   <td><img src="<%=Url.Content("~/images/icons/cross.png")%>" /></td>
                <%} %>
                <%
                if (this.Model.Attributes != null) {
                foreach(var attribute in this.Model.Attributes)
                {
                    %><td><%:user.GetAttribute(attribute) %></td><%
                }
            
                }
%>
                </tr>
            
    <%
            
            }
       }
    %>
    </tbody>
    </table>
    </div>
</asp:Content>
